﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using RATSharp.Model;

namespace RATSharpW7.Converters
{
    /// <summary>
    /// Converter for daily reservations.
    /// Just provide the corresponding reservation object
    /// ond bind colorProvider
    /// </summary>
    public class DayViewColorConverter : FrameworkElement, IValueConverter
    {
        /// <summary>
        /// Bindable color provider.
        /// </summary>
        public IDayViewColorProvider DayViewColorProvider
        {
            get { return (IDayViewColorProvider)GetValue(DayViewColorProviderProperty); }
            set { SetValue(DayViewColorProviderProperty, value); }
        }

        public static readonly DependencyProperty DayViewColorProviderProperty =
           DependencyProperty.Register("DayViewColorProvider", typeof(IDayViewColorProvider), typeof(DayViewColorConverter),
           new PropertyMetadata(null, new PropertyChangedCallback(OnOccupationsChanged)));

        private static void OnOccupationsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((DayViewColorConverter)d).OnDayViewColorProviderChanged(e);
        }

        protected virtual void OnDayViewColorProviderChanged(DependencyPropertyChangedEventArgs e)
        {
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return null;
            
            RATSharp.Model.period val = value as RATSharp.Model.period;
            if (DayViewColorProvider == null) return null;
           return DayViewColorProvider.provideColor(val);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
